import java.util.Stack;

public class Solution {

     class ListNode {
          int val;
          ListNode next;
          ListNode(int x) {
              val = x;
              next = null;
          }
     }

        public boolean hasCycle(ListNode head) {
            ListNode fast=head;
            ListNode slow=head;
            while(fast.next!=null){
                fast.next=fast.next.next;
                slow.next=slow.next;
                if(fast==slow){
                    return true;
                }
            }
            return false;
        }


    public int evalRPN(String[] tokens) {
        Stack<Integer> stack=new Stack<>();
        for (String e: tokens) {
            if(!(e.equals("+") || e.equals("-") || e.equals("*") || e.equals("/"))){
                stack.push(Integer.valueOf(e));
            }else{
                int right=stack.pop();
                int left=stack.pop();
                switch (e){
                    case "+":
                        stack.push(left + right);
                        break;
                    case "-":
                        stack.push(left - right);
                        break;
                    case "*":
                        stack.push(left * right);
                        break;
                    case "/":
                        stack.push(left / right);
                        break;
                }
                }
            }
        return stack.peek();
        }

    /**
     * 代码中的类名、方法名、参数名已经指定，请勿修改，直接返回方法规定的值即可
     *
     *
     * @param pushV int整型一维数组
     * @param popV int整型一维数组
     * @return bool布尔型
     */
    public boolean IsPopOrder (int[] pushV, int[] popV) {
        // write code here
        Stack<Integer> stack=new Stack<>();
        int j=0;
        for (int i = 0; i < pushV.length; i++) {
            stack.push(pushV[i]);
            while(stack.peek().equals(popV[i])&&j< popV.length){
                stack.pop();
                j++;
            }
        }
        if(j== popV.length){
            return true;
        }
        return false;
    }
}
